
/**
 * 重构当前vm.render业务逻辑,使用方式如下
 * import overwriteVmRender from 'mars-pro/lib/pro/mixins/overwrite-vm-render'
 * export default {
 *   mixins: [overwriteVmRender],
 *   methods: {
 *      // tag 标签
 *      // data vnode配置: 参考 https://v2.vuejs.org/v2/guide/render-function.html
 *      // child: 当前vnode子节点
 *      // vnodePath 节点路径,类似event.path
 *      handleOverwriteVmRender({tag, data, child}, vnodePath){
 *          return {
 *              ntag, ndata, nchild
 *          }
 *      }
 *   }
 * }
 * 
 * @auther: xiufu.wang
 */
export default {
    created() {
        const _vm = this
        _vm.vnodePath = []
        const _oldRender = _vm.$options.render
        _vm.$options.render = function () {
            const vnodePath = _vm.vnodePath = []
            var _h = _vm._self._c || _vm.$createElement
            _vm._self._c = _vm.$createElement = function _createElement(tag, data, child, flag) {
                vnodePath.push({
                    tag: tag,
                    data: data
                })
                if (typeof _vm.handleOverwriteVmRender === 'function') {
                    const { ntag, ndata, nchild } = _vm.handleOverwriteVmRender({ tag, data, child }, vnodePath)
                    return _h(ntag, ndata, nchild, flag)
                }
                return _h(tag, data, child, flag)
            }
            return _oldRender.call(_vm)
        }
    }
}